var time = {
	// 页面停留时间
	joinSecond : 0,
}
var joinSecond = 0;
var div = document.createElement("div");
div.id = "clock";
// 检查是不是在frame中, 如在, 则不加入日期
if (top.location != self.location) {
	return;
}
// 在body后增加提示插件
$("html > body").after($(div));
// 增加css
//
var css = "#clock{background-color:hsl(73, 99%, 36%)!important;z-index:1000!important;height:26px !important;line-height:2 !important;position:fixed !important;bottom:0px !important;width:100%!important;text-align:center !important;";
css += "color:white;font-size:14px;border-color: hsl(4, 86%, 45%);background-repeat:no-repeat;background-image:url('');background-size:5% 100%;}";
// css +="#clock{-webkit-animation:process 5s;}";
// css +="@-webkit-keyframes process { 0% {background-size:5% 100%;} 25%
// {background-size:25% 100%;} 50% {background-size:45% 100%;} 75%
// {background-size:75% 100%;} 100% {background-size:100% 100%;} }";
css += "#tmp_div{padding:0px 10px;}";

$("<style>").text(css).appendTo("head");
// console.dir($("#clock"));
$("#clock").css("backgroundSize", "0% 100%");
// background-size: 58% 100%
// 间隔
var tab = "<span id=tmp_div></span>";
// 获取格式化后的时间
function getDateTime() {
	Date.prototype.getDateTime = function() {
		var yyyy = this.getFullYear().toString();
		var MM = (this.getMonth() + 1).toString();
		var dd = this.getDate().toString();
		var HH = this.getHours().toString();
		var mm = this.getMinutes().toString();
		var ss = this.getSeconds().toString();
		var datetime = "日期时间:" + yyyy + "-" + (MM[1] ? MM : "0" + MM[0]) + "-"
				+ (dd[1] ? dd : "0" + dd[0]);
		datetime += " " + (HH[1] ? HH : "0" + HH[0]) + ":"
				+ (mm[1] ? mm : "0" + mm[0]) + ":" + (ss[1] ? ss : "0" + ss[0]);
		// datetime += tab+"当前:" + numberForamt(this.getTime());
		return datetime;
	};
	var date = new Date();
	return date.getDateTime();
}

printDate();
var refreshDateTime = window.setInterval(printDate, 993);
function printDate() {
	var dateTime = getDateTime();
	// console.info(dateTime);
	var ctx = $("#clock")[0];
	dateTime += tab
			+ "今天:"
			+ numberForamt(86400000 - (new Date().getTime() - throwsDatetime()
					.getTime()));
	dateTime += tab
			+ "所有:"
			+ numberForamt(new Date("2023-06-09 15:29:59").getTime()
					- new Date().getTime());
	dateTime += tab + "停留:" + second2Time(joinSecond) + "【" + joinSecond + "】";
	
//	debugger;
	if(joinSecond<1){
		notice(dateTime);
		console.info("Remain: "+numberForamt(new Date("2023-06-09 15:29:59").getTime()
				- new Date().getTime())+" ::Topin");
	}
	$(ctx).html(dateTime);
	joinSecond++;
}
// 今天的开始时间
function throwsDatetime() {
	var todayStart = new Date();
	todayStart.setHours(0);
	todayStart.setMinutes(0);
	todayStart.setSeconds(0);
	todayStart.setMilliseconds(0);
	return todayStart;
}
// 将秒钟化时分秒
function second2Time(second) {
	var result = "";
	var m = 60;
	var h = m * 60;
	var minutes = "";
	var hours = "";
	if (second > h) {
		hours = second / h;
		result += Math.floor(hours) + "时";
		second = Math.round(second % h);
	}
	if (second > m) {
		minutes = second / m;
		result += Math.floor(minutes) + "分";
		second = Math.round(second % m);
	}
	result += Math.round(second) + "秒";
	return result;
}
// 数字格式化
function numberForamt(x) {
	return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
// console.log(second2Time(4000));
// 增加鼠标监听事件,鼠标在上时, 不显示
$("#clock").mouseover(function() {
	$(this).fadeOut("slow");
});
$("#clock").mouseout(function() {
	$(this).fadeIn("slow");
});
// 增加滚动条上下控制是否显示
var iniScroll = $(window).scrollTop();
$(document).scroll(function() {
	if ($(this).scrollTop() > iniScroll) {
		$("#clock").fadeOut("slow");
	} else {
		$("#clock").fadeIn("slow");
	}
	iniScroll = $(document).scrollTop();
});


$(window).unload(function() {
	// debugger;
	//alert("confirm");
	console.log(joinSecond);
});

